package com.homework.controller;/**
 * @author： li
 * @date： 2021-05-18 19:23
 * @version 1.0
 */

import com.homework.bin.user;
import com.homework.service.userservice;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @author： Administrator
 * @date： 2021-05-18 19:23
 * @version 1.0
 */
@WebServlet("/register")
public class registerServlet implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        user us=new user();
        us.setUsername(username);
        us.setPassword(password);
        userservice userservice=new userservice();
        int i=0;
        i=userservice.register(us);
        if(i>0){
            req.getRequestDispatcher("/successregister.html").forward(req,res);
        }else {
            req.getRequestDispatcher("/failregister.html").forward(req,res);
        }
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
